Tarea número 03.
Alexandre Bolaños Umaña.
Carné C01229
Introducción:
En este trabajo, se creará una tabla, la cual cuenta con los registros de presencia de cuatro especies de primates que habitan nuestro territorio. Las especies son ardilla (Saimiri oerstedii), araña (Ateles geoffroyi), carablanca (Cebus capucinus) y el mono aullador (Alouatta palliata).
Dichas especies de monos, son características de nuestra diversidad biológica, tanto de flora como de fauna, lo cual genera, un panorama atractivo para los turistas que visitan nuestro país.
Preparativos.
# Carga de paquetes
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(DT)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(leaflet)
library(raster)
## Loading required package: sp
##
## Attaching package: 'raster'
## The following object is masked from 'package:plotly':
##
## select
## The following object is masked from 'package:dplyr':
##
## select
library(rgdal)
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/alexb/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/alexb/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/alexb/Documents/R/win-library/4.1/rgdal/proj
primates <-
st_read(
'https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/gbif/primates-cr-registros.csv',
options = c(
"X_POSSIBLE_NAMES=decimalLongitude",
"Y_POSSIBLE_NAMES=decimalLatitude"
),
quiet = TRUE
)
st_crs(primates) = 4326
# Datos geoespaciales de cantones
cantones <-
st_read(
"https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/ign/delimitacion-territorial-administrativa/cr_cantones_simp_wgs84.geojson",
quiet = TRUE
)
primates <-
primates %>%
st_join(cantones["canton"])
Tabla de registros de presencia.
# Tabla de registros de presencia
primates %>%
st_drop_geometry() %>%
dplyr::select(family, species, stateProvince, canton, eventDate) %>%
datatable(colnames = c(
"Familia",
"Especie",
"Provincia",
"Cantón",
"Fecha"),
options = list(searchHighlight = TRUE,
language = list(url = '//cdn.datatables.net/plug-ins/1.10.25/i18n/Spanish.json'),
pageLength = 10),
class = 'cell-border stripe'
)
Gráfico de registro.
# Asignación de paleta de color
colors <- c('#7F00B2','#007000','#fc007f')
# Gráfico
plot_ly(primates, labels = ~species, type = 'pie',
textinfo = 'label+percent',
hoverinfo = "value",
marker = list(colors = colors, line = list(color = "#ffffff", width = 1))
) %>%
layout(title = 'Porcentaje de registro de primates en Costa Rica') %>%
config(locale = "es")
## Warning: 'pie' objects don't have these attributes: 'x', 'y', 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'labels', 'label0', 'dlabel', 'values', 'marker', 'text', 'hovertext', 'scalegroup', 'textinfo', 'hoverinfo', 'hovertemplate', 'texttemplate', 'textposition', 'textfont', 'insidetextorientation', 'insidetextfont', 'outsidetextfont', 'automargin', 'title', 'domain', 'hole', 'sort', 'direction', 'rotation', 'pull', '_deprecated', 'idssrc', 'customdatasrc', 'metasrc', 'labelssrc', 'valuessrc', 'textsrc', 'hovertextsrc', 'hoverinfosrc', 'hovertemplatesrc', 'texttemplatesrc', 'textpositionsrc', 'pullsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Mapa de distribución.
A continuación debemos descargar las capas de altitud.
alt <- getData(
"worldclim",
var = "alt",
res = .5,
lon = -84,
lat = 10
)
# Capa altitud Costa Rica
altitud <- crop(alt, extent(-86, -82.3, 8, 11.3))
# Paleta de colores
pal <- colorNumeric(
c("#006400", "#FFFF00", "#3F2817"),
values(altitud),
na.color = "transparent"
)
Seguidamente, debemos crear variables y filtrarlas.
Ateles_geoffroyi <- primates %>%
filter(species == "Ateles geoffroyi")
Alouatta_palliata <- primates %>%
filter(species == "Alouatta palliata")
Cebus_capucinus <- primates %>%
filter(species == "Cebus capucinus")
Saimiri_oerstedii <- primates %>%
filter(species == "Saimiri oerstedii")
Seguido a esto, crearemos el mapa.
# Mapa de porcentajes con registros de presencia
primates %>%
dplyr::select(stateProvince,
canton,
eventDate,
species) %>%
leaflet() %>%
addProviderTiles(providers$OpenStreetMap.Mapnik, group = "OpenStreetMap") %>%
addProviderTiles(providers$Esri.WorldImagery, group = "Imágenes de ESRI") %>%
addCircleMarkers(
data = Ateles_geoffroyi,
stroke = F,
radius = 4,
fillColor = '#3cbefc',
fillOpacity = 1,
popup = paste(
primates$stateProvince,
primates$canton,
primates$eventDate,
primates$species,
sep = '<br/>'
),
group = "Ateles geoffroyi"
) %>%
addCircleMarkers(
data = Alouatta_palliata,
stroke = F,
radius = 4,
fillColor = '#f8877f',
fillOpacity = 1,
popup = paste(
primates$stateProvince,
primates$canton,
primates$eventDate,
primates$species,
sep = '<br/>'
),
group = "Alouatta palliata"
) %>%
addCircleMarkers(
data = Cebus_capucinus,
stroke = F,
radius = 4,
fillColor = '#00c87a',
fillOpacity = 1,
popup = paste(
primates$stateProvince,
primates$canton,
primates$eventDate,
primates$species,
sep = '<br/>'
),
group = "Cebus capucinus"
) %>%
addCircleMarkers(
data = Saimiri_oerstedii,
stroke = F,
radius = 4,
fillColor = '#9d64e2',
fillOpacity = 1,
popup = paste(
primates$stateProvince,
primates$canton,
primates$eventDate,
primates$species,
sep = '<br/>'
),
group = "Saimiri oerstedii"
) %>%
addRasterImage(
altitud,
colors = pal,
opacity = 0.8,
group = "Altitud"
) %>%
addLayersControl(
baseGroups = c("OpenStreetMap", "Imágenes de ESRI"),
overlayGroups = c("Altitud", "Ateles geoffroyi", "Alouatta palliata", "Cebus capucinus", "Saimiri oerstedii")
) %>%
addMiniMap(
tiles = providers$Stamen.OpenStreetMap.Mapnik,
position = "bottomleft",
toggleDisplay = TRUE
)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition